package exam;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Scanner;
import java.util.concurrent.CountDownLatch;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;


public class Main {
	
	public static String generatePwd(String str, int n, int mode, int seed)
	{
		String password ="";
		Random random = new Random(seed);
		int index;
		for(int i = 0; i < n; i++)
		{
			index = random.nextInt()%str.length();
			index = Math.abs(index);
			if(mode == 1) {
				while(password.contains(str.substring(index,index + 1))) {
					index = random.nextInt()%str.length();
					index = Math.abs(index);
				}
			}
			password += str.substring(index,index + 1);
		}
		return password;
	}
//xiugai
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int n = sc.nextInt();
		int mode = sc.nextInt();
		int seed = sc.nextInt();

		System.out.println(generatePwd(str, n, mode, seed));

		sc.close();
	}
}
